<template>
  <div class="visualarea">
    <el-form label-position="right" label-width="100px">
      <el-form-item label="垂直视场角度">
        <el-slider :max="90" @change="changeVerticalView" v-model="verticalViewAngle"></el-slider>
      </el-form-item>
      <el-form-item label="水平视场角度">
        <el-slider :max="120" @change="changeHorizontalView" v-model="horizontalViewAngle"></el-slider>
      </el-form-item>
      <el-form-item label="观察者高度">
        <el-input v-model="observerHeight">
          <template #suffix>米</template>
        </el-input>
      </el-form-item>
      <div class="panel_operate">
        <div @click="drawArea">绘制区域</div>
        <div @click="clear">清除</div>
        <div @click="exit">退出</div>
      </div>
    </el-form>
  </div>
</template>
<script setup>
import { ref,watch,reactive,toRefs  } from "vue";
import tool3dState from"@/store/modules/tool3dState"
import ViewShed from "@/utils/FCT/3dTool/viewshedAnalysis/index";
const tool3dStateStore=tool3dState();
let viewShed=undefined;
const viewObj=reactive({
    observerHeight: 0,
    verticalViewAngle: 60,
    horizontalViewAngle: 90,
})
const {observerHeight,verticalViewAngle,horizontalViewAngle}= toRefs(viewObj)
const changeObserverHeight=()=> {

}
const changeHorizontalView=(val)=> {
     if(!viewShed) return;
      viewShed.horizontalViewAngle = val;
      viewShed.add();
    }
const changeVerticalView=(val)=> {
    if(!viewShed) return;
      viewShed.verticalViewAngle =90- val;
      viewShed.add();
    };
const drawArea=()=> {
      viewShed = new ViewShed(viewer, {
          observerHeight: observerHeight.value,
          horizontalViewAngle: horizontalViewAngle.value,
          verticalViewAngle:90- verticalViewAngle.value
        });
    }
const clear=()=>{
    viewShed?.clear();
    viewShed=null;
}
const exit=()=>{
    clear();
    tool3dStateStore.updateCurrent3dState('0')
}
</script>

<style scoped lang="less">
.visualarea {
  width: 400px;
  height: 250px;
  background: #fff;
  border-radius: 5px;
  padding: 15px 22px;
  position: absolute;
  bottom: 3vh;
  left: 5vw;
  box-sizing: border-box;
  .panel_operate {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    div {
      background: #3aa6f4;
      border-radius: 4px 4px 4px 4px;
      padding: 9px 16px;
      font-size: 14px;
      cursor: pointer;
      color: #ffffff;
    }
  }
}
</style>
  